package mall.bean;

import java.util.HashMap;

/**
 * 订单的状态枚举
 * @author Administrator
 *
 */
public enum OrderState {
	TO_PAY(1, "待付款"),
	TO_SHIP(2, "待发货"),
	TO_RECEIVE(3, "待收货"),
	TO_SHOW(4, "待评价"),
	COMPLETEED(5, "已完成"),
	CANCELED(6, "已取消");

	private int value;
	private String description;
	
	OrderState(int value, String description) {
		this.value = value;
		this.description = description;
	}
	
	public int getValue() {
		return value;
	}
	
	public void setValue(int value) {
		this.value = value;
	}
	
	public String getDescription() {
		return description;
	}
	
	public void setDescription(String description) {
		this.description = description;
	}

	// int -> OrderState 的映射表
	private static HashMap<Integer, OrderState> mapping = new HashMap<Integer, OrderState>();
	
	static {
		mapping.put(OrderState.TO_PAY.getValue(), OrderState.TO_PAY);
		mapping.put(OrderState.TO_SHIP.getValue(), OrderState.TO_SHIP);
		mapping.put(OrderState.TO_RECEIVE.getValue(), OrderState.TO_RECEIVE);
		mapping.put(OrderState.TO_SHOW.getValue(), OrderState.TO_SHOW);
		mapping.put(OrderState.COMPLETEED.getValue(), OrderState.COMPLETEED);
		mapping.put(OrderState.CANCELED.getValue(), OrderState.CANCELED);
	}
	
	public static OrderState parse(int state) {
		return mapping.get(state);
	}
}









